package OpFile;

import java.io.FileOutputStream;
import java.io.BufferedOutputStream;
import java.io.FileWriter;
import java.io.File;

public class WriteToFile {
	/*
	 * test the performance of diff write file method
	 */

	public static void main(String[] args) {
		FileOutputStream out = null;
		FileOutputStream outStr = null;
		BufferedOutputStream buff = null;
		FileWriter fw = null;
		int count = 100000; // count of write ops
		try {
			byte[] bs = "test write ops of java".getBytes();
			out = new FileOutputStream(new File("D:/work/java Start/MySpace/testfile/out1.txt"));
			long begin = System.currentTimeMillis();
			for(int i = 0; i < count; i ++) {
				out.write(bs);
			}
			out.close();
			long end = System.currentTimeMillis();
			System.out.println("FileOutputStream elapse: " + (end - begin) + " ms");
				
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				fw.close();
				buff.close();
				outStr.close();
				out.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
